{$R-}

(*
	resetSPort(port number, setting) -- Reset the serial port driver.

	To compile and link this file using Macintosh Programmer's Workshop,

	pascal -w resetPort.p
	link -m ENTRYPOINT -o HyperCommands -rt XCMD=1 -sn Main=resetSPort resetPort.p.o "{MPW}"Libraries:interface.o
	
*)

{$S resetSPort } 	{ Segment name must be the same as the command name. }

unit DummyUnit;

interface

uses MemTypes, QuickDraw, OSIntf, HyperXCmd;

procedure EntryPoint(paramPtr: XCmdPtr);
	
implementation

type

Str31 = String[31];

procedure resetSPort(paramPtr: XCmdPtr); forward;

procedure EntryPoint(paramPtr: XCmdPtr);

	begin
		resetSPort(paramPtr);
	end;

procedure resetSPort(paramPtr: XCmdPtr);

	var portNumber: integer;
		setting: integer;
		inPort, outPort: integer;
		str: Str255;

	{$I XCmdGlue.inc}

	procedure Fail(errMsg: Str255); { set theResult and quit }
		begin
			paramPtr^.returnValue := PasToZero(errMsg);
			exit(resetSPort);
		end;

	begin
		if paramPtr^.paramCount <> 2 then Fail('parameter count is not 2');

		ZeroToPas(paramPtr^.params[1]^,str);		{ First parameter is port number. }
		portNumber := StrToNum(str);
		if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
		ZeroToPas(paramPtr^.params[2]^,str);		{ Second parameter is setting. }
		setting := StrToNum(str);

		if portNumber = 1 then
			begin
				inPort := -6; outPort := -7;
			end
		else
			begin
				inPort := -8; outPort := -9;
			end;
		if (SerReset(inPort,setting) <> noErr) or (SerReset(outPort,setting) <> noErr) then
			Fail('SerReset failed');
	end;

end.
